package com.yonyou.gmmc.service.wechatpush.event.handler;

import static org.marketing.common.constants.MessagePushConstant.WX_MSG_PROP_COLOR;

import java.util.Date;

import org.marketing.common.constants.BusinessConstant;
import org.marketing.common.constants.MessagePushConstant;
import org.marketing.common.dto.EventDataDTO;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocol;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageContent;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageTemplateContent;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolReceiver;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolSender;
import org.marketing.common.event.BizEvent;
import org.marketing.common.event.EventPointsChangedDTO;
import org.marketing.common.event.EventRecommandCarOrderedDTO;
import org.marketing.common.event.EventRepairOrderEvaluatedDTO;
import org.marketing.common.event.enums.EventConstant;
import org.marketing.common.event.enums.EventConstant.EventBizStep;
import org.marketing.common.event.enums.EventConstant.EventBizType;
import org.marketing.common.util.DateUtil;
import org.marketing.common.util.MapConverUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.yonyou.gmmc.service.wechatpush.dao.TmPotentialUserMapper;
import com.yonyou.gmmc.service.wechatpush.model.TmPotentialUser;
import com.yonyou.gmmc.service.wechatpush.event.exception.PushException;
import com.yonyou.gmmc.service.wechatpush.event.service.PointChangeEventService;
import com.yonyou.gmmc.service.wechatpush.util.SpringUtil;


/**
 * 推荐购车下单事件
 * 
 * @author haugii
 *
 */
public class PointChangeEventHandler extends AbstractEventHandle {

	private static Logger logger = LoggerFactory.getLogger(PointChangeEventHandler.class);
	
	private PointChangeEventService pointChangeEventService;
	@Override
	protected String getHandleInfo() {
		return "处理积分变动事件节点";
	}

	
	/**
	 * 主要进行数据转换
	 */
	@Override
	protected EventPointsChangedDTO preCheck(BizEvent event) {
		EventPointsChangedDTO o = new EventPointsChangedDTO();
		try {
			o = (EventPointsChangedDTO) MapConverUtil.map2PO(event.getEventData(), o);
			logger.info(o.toString());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			this.backInfo = "eventData中的业务数据不能识别：" + e.getMessage();
			throw new PushException(PushException.EVENT_CONVERT_FAILD,"eventData中的业务数据不能识别");
		}
		return o;
	}

	/**
	 * 模板推送处理的逻辑
	 */
	@Override
	protected boolean push(EventDataDTO eventData) throws PushException{
		pointChangeEventService=(PointChangeEventService)SpringUtil.getBean("pointChangeEventService");
		WeChatMessageProtocol t=pointChangeEventService.getWXTemplate((EventPointsChangedDTO)eventData);
		this.sendNotify(t);
		return false;
	}

	@Override
	protected void afterPush() {
		// TODO Auto-generated method stub
	}

}
